package com.seveneight.baijiesteward.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.bean.BankListBean;
import com.seveneight.baijiesteward.bean.RankListBean;
import com.seveneight.baijiesteward.http.HttpConfig;
import com.seveneight.baijiesteward.ui.main.activity.SelectBankActivity;
import com.seveneight.baijiesteward.utils.DateUtil;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 选择（银行，主题）adapter
 * Created by user1 on 2018/5/31.
 */

public class SelectBankAdapter extends BaseAdapter {
    LayoutInflater mInflater;
    List<BankListBean> listData;
    Activity activity;
    public SelectBankAdapter(Activity activity, List<BankListBean> listData){
        mInflater = LayoutInflater.from(activity);
        this.activity=activity;
        this.listData=listData;
    }

    @Override
    public int getCount() {
        return null==listData?0:listData.size();
    }
    public void refresh(List<BankListBean> listData){
        this.listData=listData;
        this.notifyDataSetChanged();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return null==listData?0:listData.size();
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_select_bank_list_layout, null); //加载布局
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {   //else里面说明，convertView已经被复用了，说明convertView中已经设置过tag了，即holder
            holder = (ViewHolder) convertView.getTag();
         }
        BankListBean item=listData.get(i);
        holder.item_bank_name.setText(item.getName());
        holder.select_icon.setVisibility(item.getSelect()?View.VISIBLE:View.GONE);
        if (null == item.getIconPath()){
            holder.icon_photo.setVisibility(View.GONE);
        }else {
            Glide.with(activity).load(item.getIconPath()).into(holder.icon_photo);
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((SelectBankActivity)activity).setSeleData(item,i);
            }
        });
        return convertView;
    }

    public class ViewHolder{
        ImageView icon_photo;
        TextView item_bank_name;
        ImageView select_icon;

        ViewHolder(View view){
            icon_photo=view.findViewById(R.id.icon_photo);
            item_bank_name=view.findViewById(R.id.item_bank_name);
            select_icon=view.findViewById(R.id.select_icon);
        }
    };
}
